﻿using System.Collections.Generic;
using HK.Core.Common;
using HK.Core.Load.Data;
using HK.Core.Load.Protocol.Data;
using HK.Core.Settings.Protocol;
using UnityEngine;
using UnityEngine.U2D;

namespace HK.Core.Load.Protocol.Pool
{
    /// <summary>
    /// 接口 : 加载缓存池
    /// </summary>
    public interface ILoadPool
    {
        /// <summary>
        /// 大小设定
        /// </summary>
        ILoadPoolSizeSettings SizeSettings { get; }

#region Ab

        /// <summary>
        /// Ab对象列表
        /// </summary>
        Dictionary<string, IAbInfo> Abs { get; }

        /// <summary>
        /// 设定信息
        /// </summary>
        /// <param name="iAbId">AbId</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iUnloadAll">Ab卸载时，是否全部卸载标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        AbInfo GenAb(string iAbId, int iOptions, bool iAsync = false,
            bool iUnloadAll = false, float iCoolTime = Const.DefaultCoolTime);

#endregion
        
#region Entity

        /// <summary>
        /// Entity对象列表
        /// <para>* Key : Entity的实例Id</para>
        /// <para>* Value : Entity对象信息</para>
        /// </summary>
        Dictionary<int, IEntityInfo> Entities { get; }

        /// <summary>
        /// 生成Entity对象信息 - 文本
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - 文本</returns>
        EntityInfo<TextAsset> GenTextEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);
        
        /// <summary>
        /// 回收Entity对象信息 - 文本
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleTextEntity(EntityInfo<TextAsset> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - 序列化对象
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - 序列化对象</returns>
        EntityInfo<ScriptableObject> GenSObjectEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - 序列化对象
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleSObjectEntity(EntityInfo<ScriptableObject> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - 序列化对象
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - 序列化对象</returns>
        EntityInfo<GameObject> GenPrefabEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - 预制体
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecyclePrefabEntity(EntityInfo<GameObject> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - Sprite
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - Sprite</returns>
        EntityInfo<Sprite> GenSpriteEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - Sprite
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleSpriteEntity(EntityInfo<Sprite> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - SpriteAtlas
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - SpriteAtlas</returns>
        EntityInfo<SpriteAtlas> GenAtlasEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - SpriteAtlas
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleAtlasEntity(EntityInfo<SpriteAtlas> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - Texture
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - Texture</returns>
        EntityInfo<Texture> GenTexEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - Texture
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleTexEntity(EntityInfo<Texture> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - Material
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - Material</returns>
        EntityInfo<Material> GenMatEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - Texture
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleMatEntity(EntityInfo<Material> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - Shader
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - Shader</returns>
        EntityInfo<Shader> GenShaderEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Entity对象信息 - Shader
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleShaderEntity(EntityInfo<Shader> iEntity);

        /// <summary>
        /// 生成Entity对象信息 - Mesh
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Entity对象信息 - Mesh</returns>
        EntityInfo<Mesh> GenMeshEntity(string iAssetKey, int iOptions,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 生成Entity对象信息
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <typeparam name="TEntity">Entity对象信息类型</typeparam>
        /// <returns>Entity对象信息</returns>
        EntityInfo<TEntity> GenEntity<TEntity>(string iAssetKey, int iOptions, bool iAsync = false,
            float iCoolTime = Const.DefaultCoolTime) where TEntity : UnityEngine.Object;

        /// <summary>
        /// 回收Entity对象信息
        /// </summary>
        /// <param name="iEntity">Entity对象信息</param>
        /// <typeparam name="TEntity">Entity对象信息类型</typeparam>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleEntity<TEntity>(EntityInfo<TEntity> iEntity) where TEntity : UnityEngine.Object;
        
#endregion

#region Asset

        /// <summary>
        /// Asset对象列表
        /// <para>* Key : AssetKey</para>
        /// <para>* Value : Asset对象信息</para>
        /// </summary>
        Dictionary<string, IAssetInfo> Assets { get; }

        /// <summary>
        /// 生成Asset对象信息 - 文本
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - 文本</returns>
        AssetInfo<TextAsset> GenTextAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - 文本
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleTextAsset(AssetInfo<TextAsset> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - 序列化对象
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - 序列化对象</returns>
        AssetInfo<ScriptableObject> GenSObjectAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - 序列化对象
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleSObjectAsset(AssetInfo<ScriptableObject> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - 序列化对象
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - 序列化对象</returns>
        AssetInfo<GameObject> GenPrefabAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - 预制体
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecyclePrefabAsset(AssetInfo<GameObject> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - Sprite
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - Sprite</returns>
        AssetInfo<Sprite> GenSpriteAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - Sprite
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleSpriteAsset(AssetInfo<Sprite> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - SpriteAtlas
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - SpriteAtlas</returns>
        AssetInfo<SpriteAtlas> GenAtlasAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - SpriteAtlas
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleAtlasAsset(AssetInfo<SpriteAtlas> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - Texture
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - Texture</returns>
        AssetInfo<Texture> GenTexAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - Texture
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleTexAsset(AssetInfo<Texture> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - Material
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - Material</returns>
        AssetInfo<Material> GenMatAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - Material
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleMatAsset(AssetInfo<Material> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - Shader
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - Shader</returns>
        AssetInfo<Shader> GenShaderAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - Shader
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleShaderAsset(AssetInfo<Shader> iAsset);

        /// <summary>
        /// 生成Asset对象信息 - Mesh
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <returns>Asset对象信息 - Mesh</returns>
        AssetInfo<Mesh> GenMeshAsset(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime);

        /// <summary>
        /// 回收Asset对象信息 - Mesh
        /// </summary>
        /// <param name="iAsset">Asset对象信息</param>
        /// <returns>true:OK; false:NG;</returns>
        bool RecycleMeshAsset(AssetInfo<Mesh> iAsset);

        /// <summary>
        /// 生成Asset对象信息
        /// </summary>
        /// <param name="iAssetKey">AssetKey</param>
        /// <param name="iOptions">选项</param>
        /// <param name="iAbId">Ab Id</param>
        /// <param name="iAsync">异步标志位</param>
        /// <param name="iCoolTime">倒计时冷却时间(默认 : 30秒)</param>
        /// <typeparam name="TAsset">Asset对象信息类型</typeparam>
        /// <returns>Asset对象信息</returns>
        AssetInfo<TAsset> GenAsset<TAsset>(string iAssetKey, int iOptions, string iAbId = null,
            bool iAsync = false, float iCoolTime = Const.DefaultCoolTime)
            where TAsset : UnityEngine.Object;

#endregion
        
    }
}
